﻿(function ($) {
    var m_pageParameter = {};

    // uesage:
    // 1. $.fn.szjt_pageParameter({....})  ==> to set(overwrite) page parameters;
    // 2. $.fn.szjt_pageParameter("para",xValue) ==> to chage one parameter with name is "para", new value is xValue;
    // 3. $.fn.szjt_pageParameter("para") ==> to get the "para" parameter value;
    // 4. $.fn.szjt_pageParameter() ==> to get all pape parameters.
    $.fn.szjt_pageParameter = function (options, param) {
        if (options == undefined) {
            return m_pageParameter;
        }

        if (typeof options == "string") {
            if (param == undefined) {
                return m_pageParameter[options];
            } else {
                m_pageParameter[options] = param;
            }
        }
        else {
            m_pageParameter = options;
        }
    }
})(jQuery);

(function ($) {
    var m_dialogParameter = {};
    var m_dialogIndex = 0;
    var m_dialog = null;

    function closeDialog() {
        var dgId = "#popDg";
        //        if ($(dgId).length > 0) {
        //            $(dgId).unbind("close");
        //            $(dgId).window("close");
        //            $(dgId).remove();
        //        }
        if (m_dialog) {
            m_dialog.window("destroy");
            m_dialog = null;
        }
    }

    $.fn.szjt_popupDialog = function (options, param) {
        if (typeof options == "string") {
            return $.fn.szjt_popupDialog.methods[options](this, param);
        }
       
        var href = options.href;
        var opts = $.extend({ editParameter: m_dialogParameter }, $.fn.szjt_popupDialog.defaults, options, $.fn.szjt_popupDialog.forces);
        //opts = $.extend(opts, { title: opts.actionName + opts.bizName });
        m_dialogIndex += 1;
        var dgId = "szjt_popDg" + m_dialogIndex;
        if ($('#' + dgId).length == 0) {
            m_dialog = $("<div id=\"" + dgId + "\" class=\"easyui-window\" ></div>");
        } else {
            //$('#' + dgId).window(opts).window('open');
            m_dialog = $('#' + dgId); //.window("refresh", "");
        }

        //m_dialog.data("editDialog", opts);
        m_dialogParameter = opts['editParameter'];
        if(m_dialogParameter.selectedList)
        {href+="?actionCode="+m_dialogParameter.actionCode+"&&selectedList="+m_dialogParameter.selectedList;}
        else
        {href+="?actionCode="+m_dialogParameter.actionCode;}
        //$("#editDialog_buttonSubmit").unbind("click").bind("click", opts.onSubmit);
        m_dialog.window(opts);
        //dialog.window("open");
        //m_dialog.window("refresh", "");
        //m_dialog.window("refresh", href);
        m_dialog.window({content: "<iframe scrolling=\"auto\" height=\"100%\" width=\"100%\" frameborder=\"0\" src=\"" + href + "\"></iframe>"});
        //$dialog.bind("close", closeDialog);
    }
    $.fn.szjt_popupDialog.methods = {
        close: function () { closeDialog(); return this; },
        editParameter: function () { return {actionCode:utility.page.getQueryString("actionCode"),selectedList:utility.page.getQueryString("selectedList")}; }
    }
    $.fn.szjt_popupDialog.defaults = { width: 500, height: 500, padding: 5,
        title: '', iconCls: 'icon-save', cache: false,
        onClose: closeDialog, onSubmit: function () { } }
    $.fn.szjt_popupDialog.forces = { modal: true, collapsible: false, minimizable: false, maximizable: false, href: '' }
})(jQuery);
